package com.hzy.kafka.entity;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class MyDelayQueue implements Delayed {

    private DelayMessage delayMessage;

    public MyDelayQueue(DelayMessage delayMessage) {
        this.delayMessage = delayMessage;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(this.delayMessage.getTime(), this.delayMessage.getUnit());
    }

    @Override
    public int compareTo(Delayed o) {
        MyDelayQueue o1 = (MyDelayQueue) o;
        return (int) (this.getDelay(this.delayMessage.getUnit()) - o1.getDelay(o1.getDelayMessage().getUnit()));
    }

    public DelayMessage getDelayMessage() {
        return delayMessage;
    }

    public void setDelayMessage(DelayMessage delayMessage) {
        this.delayMessage = delayMessage;
    }
}
